<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class CreditConfig extends \app\BaseModel
{
    protected $name = "massage_coach_credit_config";
    protected function getDistanceAttr($value, $data)
    {
        return !empty($value) ? @unserialize($value) : $value;
    }
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        if(empty($data)) {
            $this->dataAdd($dis);
            $data = $this->where($dis)->find();
        }
        return !empty($data) ? $data->toArray() : [];
    }
    public function creditRecordAdd($coach_id, $type, $uniacid, $order_id, $price = 0, $create_time = 0)
    {
        $config = $this->dataInfo(["uniacid" => $uniacid]);
        switch ($type) {
            case 1:
                $value = "order_value";
                break;
            case 2:
                $value = "add_order_value";
                break;
            case 3:
                $value = "time_long_value";
                break;
            case 4:
                $value = "repeat_order_value";
                break;
            case 5:
                $value = "good_evaluate_value";
                break;
            case 6:
                $value = "refund_order_value";
                break;
            case 7:
                $value = "refuse_order_value";
                break;
            case 8:
                $value = "bad_evaluate_value";
                break;
//            default:

        }
        $value = !empty($price) ? $config[$value] * $price : $config[$value];
        if(empty($value)) {
            return true;
        }
        $insert = ["uniacid" => $uniacid, "coach_id" => $coach_id, "order_id" => $order_id, "type" => $type, "value" => in_array($type, [6, 7, 8]) ? $value * -1 : $value, "order_price" => in_array($type, [6, 7, 8]) ? $price * -1 : $price, "create_time" => !empty($create_time) ? $create_time : time()];
        $record_model = new CreditRecord();
        $res = $record_model->dataAdd($insert);
        return $res;
    }
}

?>